/**
 * 
 */
package org.pump.client.codec;

import java.util.Arrays;

import org.apache.mina.core.buffer.IoBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author liudong03
 *
 */
public class EventHead {
	private static final Logger mylog = LoggerFactory
			.getLogger(EventHead.class);
	public static final int event_head_length = 19;
	long timestamp;
	short typecode;
	long serverid;
	long event_length;
	long next_position;
	byte[] flags = new byte[2];
	/**
	 * 
	 */
	public EventHead() {
		// TODO Auto-generated constructor stub
	}
	
	public static EventHead readbuffer(IoBuffer in)
	{
		if(in.remaining() < event_head_length)
		{
			return null;
		}
		EventHead head = new EventHead();
		head.timestamp = in.getUnsignedInt();
		head.typecode = in.getUnsigned();
		head.serverid = in.getUnsignedInt();
		head.event_length = in.getUnsignedInt();
		head.next_position = in.getUnsignedInt();
		in.get(head.flags);
		
		
		return head;
	}

	/**
	 * @return the typecode
	 */
	public short getTypecode() {
		return typecode;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "EventHead [timestamp=" + timestamp + ", typecode=" + typecode
				+ ", serverid=" + serverid + ", event_length=" + event_length
				+ ", next_position=" + next_position + ", flags="
				+ Arrays.toString(flags) + "]";
	}

	/**
	 * @return the event_length
	 */
	public long getEvent_length() {
		return event_length;
	}

	/**
	 * @return the next_position
	 */
	public long getNext_position() {
		return next_position;
	}

	/**
	 * @param typecode the typecode to set
	 */
	public void setTypecode(short typecode) {
		this.typecode = typecode;
	}
	
	
	
	
}
